package demo2lambda;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: xiaotutu
 * Date: 2025-01-16
 * Time: 17:38
 */

//无返回值无参数
@FunctionalInterface
interface NoParameterNoReturn {
    void test();
}

//无返回值一个参数
@FunctionalInterface
interface OneParameterNoReturn {
    void test(int a);
}

//无返回值多个参数
@FunctionalInterface
interface MoreParameterNoReturn {
    void test(int a,int b);
}
//有返回值无参数
@FunctionalInterface
interface NoParameterReturn {
    int test();
}
//有返回值一个参数
@FunctionalInterface
interface OneParameterReturn {
    int test(int a);
}

//有返回值多参数
@FunctionalInterface
interface MoreParameterReturn {
    int test(int a,int b);
}



public class Test {

    public static void main(String[] args) {
        int a = 10;
        //a = 1999;
        NoParameterNoReturn noParameterNoReturn = new NoParameterNoReturn(){
            @Override
            public void test() {
                //此时捕获的变量 一定是没有修改过得  或者是一个常量
                System.out.println("a = "+ a );
            }
        };
        noParameterNoReturn.test();
        NoParameterNoReturn noParameterNoReturn2 = ()->System.out.println("a ===> " + a);
        noParameterNoReturn2.test();
    }
    public static void main1(String[] args) {
        NoParameterNoReturn noParameterNoReturn = ()-> {
            System.out.println("无参数无返回值");
        };
        OneParameterNoReturn oneParameterNoReturn = x-> System.out.println(x);
        oneParameterNoReturn.test(10);
        System.out.println("=======");
        MoreParameterNoReturn moreParameterNoReturn = (x,y) -> System.out.println(x+y);
        moreParameterNoReturn.test(10,20);
        System.out.println("=======");

    }
}
